<template>
    <div class="shorpcar-container">
        <!--商品列表-->
        <div class="goods-list">
            <div v-for="item in carList" class="mui-card">
                <div class="mui-card-content">
                    <div class="mui-card-content-inner">
                        <mt-switch v-model="$store.getters.getGoodsSelected[item.id]" @change="upSelected(item.id,$store.getters.getGoodsSelected[item.id])"></mt-switch>
                        <img :src="item.thumb_path">
                        <div class="info">
                            <h4 class="title">{{item.title}}</h4>
                            <div>
                                <span class="price">￥{{item.sell_price}}</span>
                                <div class="mui-numbox">
                                    <!-- "-"按钮，点击可减小当前数值 -->
                                    <button class="mui-btn mui-numbox-btn-minus" type="button">-</button>
                                    <input class="mui-numbox-input" type="number" :value="$store.getters.getItemCount[item.id]"/>
                                    <!-- "+"按钮，点击可增大当前数值 -->
                                    <button class="mui-btn mui-numbox-btn-plus" type="button">+</button>
                                </div>
                                <a @click.passive="remove(item.id)" class="fl-right">删除</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--结算区域-->
        <div class="mui-card">
            <div class="mui-card-content">
                <div class="mui-card-content-inner settlement">
                    <div class="left">
                        <p>
                            总计(不含运费)
                        </p>
                        <p>
                            已勾选商品<span> {{$store.getters.getGoodsCountAndAmount.count}} </span>价 ,总价: <span>￥{{$store.getters.getGoodsCountAndAmount.amount}}</span>
                        </p>
                    </div>
                    <div class="right">
                        <mt-button type="danger">去结算</mt-button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import mui from '../../../lib/mui/js/mui.min';
    import connector from '../../base/interface.js';
    import { Toast } from 'mint-ui';
    export default {
        data(){
            return{
                carList:[]
            }
        },methods:{
            getGoodsList(){
                /*获取购物车中商品列表*/
                var ids=[];
                this.$store.state.shpCar.forEach(item=>ids.push(item.id));
                if(!ids.length){
                    Toast("购物车中空空如也");
                    return false;
                }
                connector.getShopCarList(ids).then(result=>{
                    this.carList=result;
                },err=>{
                    Toast("请求出错!!!");
                })
            },
            remove(id){
                /*删除购物车中的商品*/
                this.carList.forEach((item,index)=>{
                    if(item.id == id){
                        this.carList.splice(index,1);
                        this.$store.commit('remozeFormCar',id);
                    }
                })
            },
            upSelected(id,selected){
                /*商品状态选中触发的方法*/
                this.$store.commit('updateGoodsSelected',{id:id,selected:selected});
            }
        },created(){
            this.getGoodsList();

        },mounted(){
            mui(".mui-numbox").numbox();
        }
    }
</script>

<style scoped lang="scss">
@import "../../base/baseRem.scss";
.shorpcar-container{
    .mui-card-content-inner{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px;
    }
    .mui-numbox{
        height: 25px;
    }
    .title{
        font-size: 14px;
        padding: 5px;
        line-height: remFu(20);
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        word-break: break-all;
    }
    img{
        width: remFu(60);
        height: remFu(60);
    }
    .info{
        .price{
            color: red;
            font-weight: bold;
        }
    }
    .settlement{
        span{
            color: red;
            font-weight: bold;
            font-size: 16px;
        }
    }
}

</style>